import java.util.Arrays;
import java.util.Stack;

/**
 * Created by zhangjinrui on 17/6/27.
 */

public class Solution388 {

    public static void main(String args[]) {
        Solution388 s = new Solution388();
        System.out.println(s.lengthLongestPath("dir\n\tfile.txt"));
    }

    public int lengthLongestPath(String input) {
        int l;
        Stack<Integer> stack = new Stack<>();
        String[] w = input.split("\\\n");
        stack.push(w[0].length());
        int len = w[0].length();
        int maxv = w[0].contains(".") ? w[0].length() : 0;
        l = 0;
        for (int i = 1; i < w.length; i++) {
            int pre = 0;
            for(int j = 0 ;true ; j ++){
                if(w[i].charAt(j) == '\t'){
                    pre ++;
                }else{
                    w[i] = w[i].substring(j);
                    break;
                }
            }

            while(l >= pre){
                int t = stack.pop();
                len -= t;
                l --;
            }
            stack.push(w[i].length() + 1);
            len += (w[i].length() + 1);
            l ++;
            if(w[i].contains(".")){
                maxv = maxv > len ? maxv : len;
            }
        }
        return maxv;
    }

}
